from flask import Blueprint, request
from conn_mysql import ConnectMysql


app_last_order_id = Blueprint('app_last_order_id', 'api')

@app_last_order_id.route('/app_last_order_id')
def last_order_id():

    user_id = request.args.get('user_id')

    # print(user_id)

    sql = 'SELECT * FROM call_car WHERE user_id=%s ORDER BY id DESC LIMIT 0,1'

    with ConnectMysql()  as c:

        result = c.select_one(sql, (user_id,))

        if not result:

            result = {}

    
    return {
        "status": 1,
            "errorCode": None,
            "errorMsg": None,
            "resultBody": {
                'last_order_id': result.get('id'),
            }
    }

